SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].gspEmailTemplate_SEARCH
(
@templateId int = null,
@subject nvarchar(150) = null,
@content nvarchar(MAX) = null,
@templateType int = null,
@createDate datetime = null,
@lastModifiedDate datetime = null
)
AS

SELECT
  *
FROM
  [dbo].[EmailTemplate]
WHERE
  (@templateId IS NULL OR [TemplateId] = @templateId)
AND
  (@subject IS NULL OR @subject = '' OR [Subject] LIKE @subject + '%')
AND
  (@templateType IS NULL OR [TemplateType] = @templateType)
AND
  (@createDate IS NULL OR [CreateDate] = @createDate)
AND
  (@lastModifiedDate IS NULL OR [LastModifiedDate] = @lastModifiedDate)

GO
